﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Weight.Model;
using Weight.Dal;

namespace Weight.Bll
{
    public  class BllRole
    {
        /// <summary>
        /// 查詢所有角色
        /// </summary>
        /// <returns></returns>
        public IEnumerable<RoleEntity> QueryAll(string name="")
        {
            return  new DalRole().QueryAll(name);
        }

       

        /// <summary>
        /// 通过名字查询角色
        /// </summary>
        /// <param name="name">名称</param>
        /// <returns></returns>
        public IEnumerable<RoleEntity> QueryByName(string name)
        {
            return new DalRole().QueryByName(name);
        }

        /// <summary>
        /// 根据Id查找角色
        /// </summary>
        /// <param name="id">角色编号</param>
        /// <returns></returns>
        public RoleEntity QueryById(string id)
        {
            return new DalRole().QueryById(id).FirstOrDefault();
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool Add(RoleEntity entity)
        {
            return new DalRole().Add(entity);
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool Update(RoleEntity entity)
        {
            return new DalRole().Update(entity);
        }

        /// <summary>
        /// 不同编号统一名称的是否存在
        /// </summary>
        /// <param name="name">角色名称</param>
        /// <param name="noThisId">角色编号</param>
        /// <returns></returns>
        public bool isExist(string name, string noThisId)
        {
            var entitys = new DalRole().QueryByName(name, noThisId);
            if(entitys.Count() > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public bool Delete(string Id)
        {
            return new DalRole().Delete(Id);
        }
    }
}
